import axios from 'axios'
import * as types from './action-types'

export const getInputChangeAction = value => ({
  type: types['INPUT_CHANGE'],
  value
})

export const getButtonClickAction = value => ({
  type: types['BUTTON_CLICK'],
  value
})

export const getDeleteClickAction = value => ({
  type: types['DELETE_CLICK'],
  value
})

export const initListAction = value => ({
  type: types['INIT_LIST'],
  value
})

export const getInitListAction = value => ({
  type: types['GET_INIT_LIST'],
  value
})

export const getList = () => {
  return dispatch => {
    axios.get('/api/todolist')
      .then(res => {
        const action = initListAction(res.data.result)
        dispatch(action)
      })
  }
}
